#!/usr/bin/python3.4
# -*- coding=utf-8 -*-
#本脚由亁颐堂现任明教教主编写，用于乾颐盾Python课程！
#教主QQ:605658506
#亁颐堂官网www.qytang.com
#乾颐盾是由亁颐堂现任明教教主开发的综合性安全课程
#包括传统网络安全（防火墙，IPS...）与Python语言和黑客渗透课程！

import paramiko
import re

def ssh_connect(ip, passwd, user = 'root', cmd = 'cat /etc/shadow | grep root', port = 22):
    try:
		ssh = paramiko.SSHClient()
		ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
		ssh.connect(ip,port,user,passwd,timeout=5)
		stdin,stdout,stderr = ssh.exec_command(cmd)
		x = stdout.read().decode()
		return (1,x)
	except Exception as e:
		if re.search('Authentication failed.', str(e)):
			return (0,'密码或者用户名错误')
		else:
			return (0,e)

if __name__ == '__main__':
	print(ssh_connect('202.100.1.139', 'Cisc01222', 'root'))

"""
[root@Fedora hacker]# ./ssh.py 
(1, 'root:$6$LJWOujALo/so9DC2$pCnOrVW8Oo0HCgKqcbL6SsTSb28KGqDSNGmCePQvXliUXx18b.PD4aU50X.DAlNMKx9Jq.RUBsxWLtW1YFM0D0::0:99999:7:::\n')
[root@Fedora hacker]# ./ssh.py 
(0, '密码或者用户名错误')
"""